﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace RH.EBS.Core.Repository.DBUtility
{
    public enum LOG_CATEGORY
    {
        DB_ACCESS,
        WEB_UI,
        WIN_UI,
        WEB_SERVICE,
        SYSTEM
    }

    public enum LOG_LEVEL
    {
        DEBUG = 0,
        // 调试信息
        INFO,
        // 常规信息
        WARNING,
        // 警告信息
        ERROR // 错误信息
        ,
    }

    public class LogWriter
    {
        public static void Write(LOG_CATEGORY Category, LOG_LEVEL Level, string Message, string Title)
        {
            LogEntry logEntry = new LogEntry();
            logEntry.EventId = Convert.ToInt32(Level);
            logEntry.Priority = Convert.ToInt32(Level);
            logEntry.Message = Message;
            logEntry.Title = Title;
            logEntry.Categories.Clear();

            switch (Category)
            {
                case LOG_CATEGORY.DB_ACCESS:
                    logEntry.Categories.Add("Data Access Log");
                    break;
                case LOG_CATEGORY.WEB_UI:
                    logEntry.Categories.Add("WebUI Log");
                    break;
                case LOG_CATEGORY.WIN_UI:
                    logEntry.Categories.Add("WinUI Log");
                    break;
                case LOG_CATEGORY.WEB_SERVICE:
                    logEntry.Categories.Add("WebService Log");
                    break;
                case LOG_CATEGORY.SYSTEM:
                    logEntry.Categories.Add("System Log");
                    break;
            }

            Logger.Write(logEntry);
        }

        public static void Write(LOG_CATEGORY Category, LOG_LEVEL Level, string Message)
        {
            LogWriter.Write(Category, Level, Message, "No Title");
        }
    }
}
